package com.limedia.explorer.http;

import java.io.IOException;
import java.util.logging.Logger;

import android.content.Context;
import android.util.Log;

import com.limedia.explorer.entity.HttpParams;
import com.limedia.explorer.http.HttpClient.ResultCallback;


public class HttpManager {
	
	private static HttpManager mInstance = null;
	private static String TAG = HttpManager.class.getSimpleName();
	
	private HttpClient httpClient = null;
	private Logger logUtils = null;
	
	private HttpManager() {
		super();
	}
	
	public static synchronized HttpManager getInstance() {
		if(null == mInstance) {
			mInstance = new HttpManager();
		}
		return mInstance;
	}
	
	public void initClient(Context context) {
		if(null == httpClient) {
			httpClient = HttpClient.getInstance(context);
		}
	}
	
	public void get(Context context, String url, ResultCallback callback, HttpParams header, Object tag) {
		if(null != this.httpClient) {
			try {
				HttpClient.getAsyn(context, url, callback, header, tag);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			Log.e(TAG, "get(), httpClient is null!");
		}
	}
	
	public void post(Context context, String url, ResultCallback callback, HttpParams header, HttpParams param, Object tag) {
		if(null != this.httpClient) {
			try {
				HttpClient.postAsyn(context, url, callback, header, param, tag);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			Log.e( TAG, "post(), httpClient is null!");
		}
	}
	
	public void post(Context context, String url, ResultCallback callback, HttpParams header, String json, Object tag) {
		if(null != this.httpClient) {
			try {
				HttpClient.postAsyn(context, url, callback, header, json, tag);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			Log.e(TAG, "post(), httpClient is null!");
		}
	}
}
